package zwo.controller;

import zwo.dao.ProductMapper;
import zwo.model.Product;
import zwo.model.dto.ProductDTO;
import zwo.service.ProductService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/admin/product")
public class ProductController {
    @Resource
    private ProductService productService;
    @Resource
    private ProductMapper productMapper;

    @ResponseBody
    @RequestMapping("/productAll.do")
    public Map productAll(ProductDTO productDTO) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", "0");
        map.put("msg", "");
        map.put("count", productMapper.productCount(productDTO));
        map.put("data", productMapper.productAll(productDTO));
        return map;
    }

    @ResponseBody
    @RequestMapping("/productAdd.do")
    public Integer productAdd(Product product) {
        return productService.productAdd(product);
    }

    @ResponseBody
    @RequestMapping("/productDelete.do")
    public Integer productDelete(Product product) {
        return productService.productDelete(product);
    }

    @ResponseBody
    @RequestMapping("/productEdit.do")
    public Integer productEdit(Product product) {
        return productService.productEdit(product);
    }

    @ResponseBody
    @RequestMapping("/productEditisPutOnSales.do")
    public Integer productEditisPutOnSales(Product product) {
        return productService.productEditisPutOnSales(product);
    }

    @ResponseBody
    @RequestMapping("/productEditisToday.do")
    public Integer productEditisToday(Product product) {
        return productService.productEditisToday(product);
    }


    @ResponseBody
    @RequestMapping("/product_state.do")
    public Integer product_state(Product product) {
        return productMapper.product_state(product);
    }

}
